package com.youchuang.action.indent;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Indent;
import com.youchuang.bean.IndentItem;
import com.youchuang.common.Constant;
import com.youchuang.service.IndentService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 用户支付
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/indent")
@ParentPackage("shopping-default")
public class IndentViewAction extends BaseAction {
	private Logger logger = Logger.getLogger(IndentViewAction.class.getSimpleName());

	private String id;
	private Indent indent;
	private List<IndentItem> items;
	
	@Resource
	private IndentService indentService;

	@Actions({
			@Action(value = "payIndent", interceptorRefs = { @InterceptorRef(value = "loginStack") }, results = {
					@Result(name = Constant.SUCCESS, location = "/WEB-INF/jsp/indent/indent_payment.jsp") }),
			@Action(value = "indentContext", results = {
					@Result(name = Constant.SUCCESS, location = "/WEB-INF/jsp/ad/indentcontext.jsp"), }) })
	public String execute() throws Exception {
		logger.info("method is execute");
		indent = indentService.findIndentById(id);
		items = indentService.findIndentItemByIndentId(id);
		logger.info("response json indent =" + JSONObject.fromObject(indent).toString());
		logger.info("response json items =" + JSONArray.fromObject(items).toString());
		return Constant.SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Indent getIndent() {
		return indent;
	}

	public void setIndent(Indent indent) {
		this.indent = indent;
	}

	public List<IndentItem> getItems() {
		return items;
	}

	public void setItems(List<IndentItem> items) {
		this.items = items;
	}
}
